package com.tc.zigbee.entity.device.ha;

import com.tc.gateway.device.ha.ColorDimmableLight;
import com.tc.gateway.device.listener.OnoffLevelListener;
import com.tc.zigbee.entity.Endpoint;
import com.tc.zigbee.entity.device.ZigbeeDevice;
import com.tc.zigbee.mt.MtCommand;
import com.tc.zigbee.mt.RequestQueue;
import com.tc.zigbee.mt.ZigbeeManager;
import com.tc.zigbee.mt.request.RequestFactory;
import com.tc.zigbee.zcl.ZclCommandCreator;
import com.tc.zigbee.zcl.ZclConstants;

public class ZigbeeColorDimmableLight extends ZigbeeDevice<OnoffLevelListener> implements ColorDimmableLight{

	public ZigbeeColorDimmableLight(Endpoint endpoint,ZigbeeManager m) {
		super(endpoint,m);

	}

	public void action() {
		// TODO Auto-generated method stub

	}
	public void action(int progress){
		byte[] zclcommand = ZclCommandCreator.moveToLevel(
				(byte)0,
				(byte)progress,
				(short)0,
				true
			);
	MtCommand mc = RequestFactory.MtAfDataRequest(
			(byte)2,
			endpoint.getParent().getNwkAddress(), 
			//(short)1,
			endpoint.getEndpointId(), 
			(byte)manager.remoteControl.getEndpointId(), 
			ZclConstants.ZCL_CLUSTER_ID_GEN_LEVEL_CONTROL, 
			(byte)0, 
			(byte)0, 
			(byte)2, 
			(byte)zclcommand.length, 
			zclcommand
			);
	RequestQueue.offer(mc);
	}
	public void toggle(){

		byte[] zclcommand = ZclCommandCreator.toggle((byte)0);
		MtCommand mc = RequestFactory.MtAfDataRequest((byte)2,
				endpoint.getParent().getNwkAddress(), 
				//(short)1,
				endpoint.getEndpointId(), 
				(byte)manager.remoteControl.getEndpointId(), 
				ZclConstants.ZCL_CLUSTER_ID_GEN_ON_OFF, 
				(byte)0, 
				(byte)0, 
				(byte)2, 
				(byte)zclcommand.length, 
				zclcommand
				);
		RequestQueue.offer(mc);
		onoff = !onoff;
		for(OnoffLevelListener l : this.listeners)
			l.onChange(onoff);
		
	}
	

	public void level(double value) {
		// TODO Auto-generated method stub
		
	}

	public void off() {
		// TODO Auto-generated method stub
		
	}

	public void on() {
		// TODO Auto-generated method stub
		
	}
	boolean onoff;
	@Override
	public boolean getOnOff() {
		// TODO Auto-generated method stub
		return onoff;
	}
	double level;
	@Override
	public double getLevel() {
		// TODO Auto-generated method stub
		return level;
	}


	
	

}
